package com.zyh.day02.value

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object AggregateTest {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setAppName("mr")
      .setMaster("local[*]")
    val sc = new SparkContext(conf)

    val rdd1: RDD[(String, Int)] = sc.makeRDD(List(("one", 1), ("two", 1), ("two", 1), ("three", 1), ("three", 1), ("three", 1), ("four", 1), ("four", 1), ("four", 1), ("four", 1)), 2)
    val rdd2: RDD[(String, Int)] = rdd1.aggregateByKey(0)((v1, v2) => v1 + v2,(v1,v2)=>v1+v2)
    rdd2.collect().foreach(println)

    sc.stop()
  }
}
